package cn.itcast.springboot.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    public static final String QUEUE1="pubsub_log";
    public static final String QUEUE2="pubsub_baojing";
    public static final String EXCHANGE="bajing_exchange";

    @Bean(QUEUE1)
    public Queue getQueue1(){
        return new Queue(QUEUE1,true,false,false);
    }

    @Bean(QUEUE2)
    public Queue getQueue2(){
        return new Queue(QUEUE2,true,false,false);
    }

    @Bean(EXCHANGE)
    public Exchange getExchange(){
        return ExchangeBuilder.directExchange(EXCHANGE).durable(true).build();
    }

    //绑定关系
    @Bean
    public Binding queue1_exchange(@Qualifier(QUEUE1) Queue queue,
                                   @Qualifier(EXCHANGE) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("error").noargs();
    }

    @Bean
    public Binding queue2_exchange(@Qualifier(QUEUE2) Queue queue,
                                   @Qualifier(EXCHANGE) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("info").noargs();
    }
    @Bean
    public Binding queue2_exchange1(@Qualifier(QUEUE2) Queue queue,
                                   @Qualifier(EXCHANGE) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("error").noargs();
    }
    @Bean
    public Binding queue2_exchange2(@Qualifier(QUEUE2) Queue queue,
                                   @Qualifier(EXCHANGE) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("warning").noargs();
    }

}
